package team.away.android.fubway;

public class StationLocation{
	private final float VALID_DISTANCE=40;

	public String getName(int id){
		String name;
		switch(id){
			case 1:name="XIZIMEN";break;
			case 2:name="XIEJIEKOU";break;
			case 3:name= "ANDINGMEN";break;
			case 4:name= "YONGHEGONG";break;
			case 5:name= "DONGZIMEN";break;
			case 6:name= "GUOMAO";break;
			case 7:name= "CONGWENMEN";break;
			case 8:name= "QIANMEN";break;
			case 9:name= "XUANWUMEN";break;
			case 10:name= "FUXINMEN";break;
			case 11:name= "XIDAN";break;
			case 12:name= "WANGFUJING";break;
			case 13:name= "JIANGUOMEN";break;
			case 14:name= "ZUO";break;
			default:name= "";break;
		}
		return name;
	}
	private static float[][] stationPositions= {
		{0, 2000, 2000}, {1, 127, 153}, {2, 203, 154}, 
		{3, 308, 89}, {4, 516, 90}, {5, 612, 141}, 
		{6, 610, 311}, {7, 517, 382}, {8, 328, 379}, 
		{9, 205, 379}, {10, 125, 309}, {11, 205, 309},
		{12, 401, 309}, {13, 513, 306}, {14, 645, 396} };
		
		
		
	public static float getX(int id){
		return stationPositions[id][1];
	}
	public static float getY(int id){
		return stationPositions[id][2];
	}
	
	
	public int getId(float x, float y){
		int id=0;
		float[] lengthX = new float[15];
		float[] lengthY = new float[15];
		lengthX[0] = VALID_DISTANCE;
		lengthY[0] = VALID_DISTANCE;
		for(int i=1; i<15; i++){
			lengthX[i] = Math.abs( x - StationLocation.getX(i) );
			lengthY[i] = Math.abs( y - StationLocation.getY(i) );
			if(lengthX[i]<lengthX[0] && lengthY[i]<lengthY[0] ){
				id=i;
				lengthX[0]=lengthX[i];
				lengthY[0]=lengthY[i];
			}
		}
		return id;
	}
	
	
	public int getId(){
		return _stationId;
	}
	
	public boolean isInvalid() {
		return getId() == 0 || isGo();
	}
	public boolean isGo(){
		return getId() == 14;
	}
	public float getX(){
		return getX(getId());
	}
	public float getY(){
		return getY(getId());
	}
	
	private int _stationId;;
	public StationLocation(float x, float y){
		this._stationId = getId(x, y);
	}
	
}